package com.cnfangmao.masterdata.common.utils;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

import com.cnfangmao.masterdata.model.Account;
import com.cnfangmao.masterdata.model.Permission;


public class UserUtil {

	public static Account getCurrentUser() {
		Account account = (Account) getSession().getAttribute("login_user");

		return account;
	}

	public static void setUserSession(Account account) {
		getSession().setAttribute("login_user", account);
	}

	@SuppressWarnings("unchecked")
	public static List<Permission> getCurrentPermissions() {
		List<Permission> list = (List<Permission>) getSession().getAttribute("user_permissions");

		return list;
	}

	public static void setPermissionSession(List<Permission> list) {
		getSession().setAttribute("user_permissions", list);
	}

	public static Session getSession() {
		Subject currentUser = SecurityUtils.getSubject();
		Session session = currentUser.getSession();

		return session;
	}
}
